package com.wxm.killing.mq.common.auth;

import com.wxm.killing.mq.common.exception.BaseException;

/**
 * @Description TODO
 * @author: wxm
 * @date: 2019/10/27 13:58
 * @version: 1.0
 */
public class UserUtil {

    public static Integer getUserId(){
        UserInfo userInfo = UserInfoContext.getUserInfo();
        Integer userId ;
        if(userInfo != null){
            userId = userInfo.getUserId();
        }else {
            throw new BaseException(0,"系统异常");
        }
        return userId;
    }

    public static UserInfo getUserInfo() throws BaseException {
        UserInfo userInfo = UserInfoContext.getUserInfo();
        if(userInfo == null){
            throw new BaseException(0,"系统异常");
        }
        return userInfo;
    }

    public static String getIp(){
        UserInfo userInfo = UserInfoContext.getUserInfo();
        String ip ;
        if(userInfo != null){
            ip = userInfo.getIp();
        }else {
            throw new BaseException(0,"系统异常");
        }
        return ip;
    }
}
